﻿<%@ WebHandler Language="C#" Class="SYS_Store_update" %>

using System;
using System.Web;
using System.Web.Script.Serialization;
using System.Collections.Generic;
using System.Web.SessionState;

public class SYS_Store_update : IHttpHandler,IRequiresSessionState {
    sqlhelp sql = new sqlhelp();
    result result = new result();
    string str = "";
    System.Data.DataTable dt = new System.Data.DataTable();
    public void ProcessRequest (HttpContext context) {
        try
        {
            if (context.Session["comid"] == null)
            {
                result.code = "-1";
                result.msg = "用户未登录";
                unit.send(context, result);
                return;
            }

            string Id = context.Session["comid"].ToString();
            System.Data.DataTable dtRecord = sql.myDataSet("select Avatar from SYS_Store where Id = '" + Id + "'").Tables[0];
            if (dtRecord.Rows.Count == 0)
            {
                result.code = "0";
                result.msg = "无数据记录";
                unit.send(context, result);
                return;
            }
            string updateStr = "";
            
            string Name = "";
            if (context.Request["Name"] != null)
            {
                Name = context.Request["Name"].ToString();
                updateStr = updateStr + " Name = '" + Name + "',";
            }
            string AuthorizeFlg = "";
            if (context.Request["AuthorizeFlg"] != null)
            {
                AuthorizeFlg = context.Request["AuthorizeFlg"].ToString();
                updateStr = updateStr + " AuthorizeFlg = " + AuthorizeFlg + ",";
            }
            string Tel = "";
            if (context.Request["Tel"] != null)
            {
                Tel = context.Request["Tel"].ToString();
                updateStr = updateStr + " Tel = '" + Tel + "',";
            }
            string UserName = "";
            if (context.Request["UserName"] != null)
            {
                UserName = context.Request["UserName"].ToString();
                updateStr = updateStr + " UserName = '" + UserName + "',";
            }
            string PassWord = "";
            if (context.Request["PassWord"] != null)
            {
                PassWord = context.Request["PassWord"].ToString();
                updateStr = updateStr + " PassWord = '" + PassWord + "',";
            }
            string Website = "";
            if (context.Request["Website"] != null)
            {
                Website = context.Request["Website"].ToString();
                updateStr = updateStr + " Website = '" + Website + "',";
            }
            string PublicNum = "";
            if (context.Request["PublicNum"] != null)
            {
                PublicNum = context.Request["PublicNum"].ToString();
                updateStr = updateStr + " PublicNum = '" + PublicNum + "',";
            }
            string Address = "";
            if (context.Request["Address"] != null)
            {
                Address = context.Request["Address"].ToString();
                updateStr = updateStr + " Address = '" + Address + "',";
            }
            string LinkTel = "";
            if (context.Request["LinkTel"] != null)
            {
                LinkTel = context.Request["LinkTel"].ToString();
                updateStr = updateStr + " LinkTel = '" + LinkTel + "',";
            }
            string Qualification = "";
            if (context.Request["Qualification"] != null)
            {
                Qualification = context.Request["Qualification"].ToString();
                updateStr = updateStr + " Qualification = '" + Qualification + "',";
            }
            string Licence = "";
            if (context.Request["Licence"] != null)
            {
                Licence = context.Request["Licence"].ToString();
                updateStr = updateStr + " Licence = '" + Licence + "',";
            }
            string Avatar = "";
            if (context.Request["Avatar"] != null)
            {
                Avatar = context.Request["Avatar"].ToString();
                
            }
            string NewPhoto = "";
            if (context.Request["NewPhoto"] != null)
            {
                NewPhoto = context.Request["NewPhoto"].ToString();
                updateStr = updateStr + " NewPhoto = '" + NewPhoto + "',";
            }

            if (updateStr == "")
            {
                result.code = "0";
                result.msg = "未传递修改参数";
                unit.send(context, result);
                return;
            }
            updateStr = updateStr.TrimEnd(',');

            str = "update SYS_Store set " + updateStr + " where Id = '" + Id + "'";
            if (sql.ExecuteNonQuery(str) > 0)
            {
                if (Avatar != "") {
                    str = "delete from SYS_Image where  Linkid = '" + dtRecord.Rows[0]["Avatar"].ToString() + "'";
                    sql.ExecuteNonQuery(str );
                    str = "insert into SYS_Image(Id,Linkid,Path,CreateTime,Enable) values('" + Guid.NewGuid().ToString() + "','" + dtRecord.Rows[0]["Avatar"].ToString() + "','" + Avatar + "','" + DateTime.Now.ToString() + "',1)";
                    sql.ExecuteNonQuery(str);
                    
                }
                result.code = "1";
                result.msg = "";
                unit.send(context, result);
            }
            else
            {
                result.code = "0";
                result.msg = "修改失败";
                unit.send(context, result);
            }
        }
        catch (Exception e1)
        {
            result.code = "0";
            result.msg = e1.Message;
        }
		
    }

    public bool IsReusable {
        get {
            return false;
        }
    }

}
